/**
 首页右侧消息通知模块儿
 功能代码
 */
var messageData=[];
var messageType="getSyTzggList";
$('.home-top-right>.tab-item-box').on('click','li',function(){
    if(!$(this).hasClass('tab-active')){
        $(this).addClass('tab-active').siblings().removeClass('tab-active');
        var arg=$(this).data("arg");
        messageType=arg;
        getMessageList(arg)
    }
});
function getMessageList(arg){
    $('.data-loading').css('display','block');
    $('.message-content').html("");
    $.ajax({
        url: "/basic/tzgg/"+arg,
        type: "GET",
        dataType: "json",
        success: function (data) {
            $('.data-loading').css('display','none');
            messageData=data.data;
            var htmlStr='';
            if(data.data.length){
                if(data.data.length<=10){
                    for(var i=0,len=data.data.length;i<len;i++){
                        htmlStr+="<li title='"+data.data[i].title+"'>";
                        if(data.data[i].titlecolor=='1'){
                            htmlStr+="<div style='height: 16px;width: 58%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #ff0000;' class=\"fl\"><i>•</i>"+data.data[i].title+"</div>";
                        }else {
                            htmlStr+="<div style='height: 16px;width: 58%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' class=\"fl\"><i>•</i>"+data.data[i].title+"</div>";
                        }
                        if(data.data[i].new=="2"){
                            htmlStr+="<span class='fl' style='font-size:10px;margin-left:10px;background: orangered;color: #fff;border-radius: 8px 8px 8px 0;'>&nbsp;new &nbsp;</span>";
                        }
                        htmlStr+="<p class=\"fr\">"+data.data[i].adddate+"</p>";
                        htmlStr+="</li>";
                    }
                }else {
                    for(var i=0;i<10;i++){
                        htmlStr+="<li title='"+data.data[i].title+"'>";
                        if(data.data[i].titlecolor=='1'){
                            htmlStr+="<div style='height: 16px;width: 58%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #ff0000;' class=\"fl\"><i>•</i>"+data.data[i].title+"</div>";
                        }else {
                            htmlStr+="<div style='height: 16px;width: 58%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' class=\"fl\"><i>•</i>"+data.data[i].title+"</div>";
                        }
                        if(data.data[i].new=="2"){
                            htmlStr+="<span class='fl' style='font-size:10px;margin-left:10px;background: orangered;color: #fff;border-radius: 8px 8px 8px 0;'>&nbsp;new &nbsp;</span>";
                        }
                        htmlStr+="<p class=\"fr\">"+data.data[i].adddate+"</p>";
                        htmlStr+="</li>";
                    }
                }
                var addFrame1 = document.getElementById("addFrame");
                if(addFrame1){
                    var addFrame = document.getElementById("addFrame").contentWindow;
                    var ifmObj6 = addFrame.document.getElementById("content");
                    if(ifmObj6!=null){
                        ifmObj6.innerHTML = htmlStr;
                    }
                } else {
                    $('.message-content').html(htmlStr);
                }
            } else {
                htmlStr+='<div>';
                htmlStr+='<img style=\"display: block;margin: 25% auto 5%;" width="50%" src="/static/images/data-empty.png"/>';
                htmlStr+='<div style="margin-top:50px;text-align: center;font-size: 16px;">暂无消息</div>';
                htmlStr+='</div>';
                $('.message-content').html(htmlStr);
            }
        },
        error:function (state) {
            $('.data-loading').css('display','none');
            var htmlStr="<div style='margin-top:50px;text-align: center;font-size: 16px;'>请求异常_ _("+state.status+")</div>";
            $('.message-content').html(htmlStr);
        }
    });
}

// 父页面调用子iframe中的方法，获取消息通知模块儿数据
function subGetMessageList(){
    getMessageList(messageType);
}

$(function(){
    getMessageList(messageType);
    // 通知公告点击时
    $('.message-content').on('click','li',function(){
        var aaa = document.getElementById("aaaa").getElementsByClassName("tab-item tab-active")[0];
        var tabname = aaa.textContent;
        $('.tankuang').addClass('tankuang-active');
        $('.content').scrollTop(0);
        var _index=$(this).index();
        if(tabname=="系统通知"){
            var tkData=[]
            $.ajax({
                url: "/basic/tzgg/"+"getXttzList",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    tkData=data.data[_index]
                    $('.title').html(tkData.title);
                    $('.adddate').html(tkData.adddate);
                    $('.fbdw').html(tkData.fbdw);
                    $('#content123').html(tkData.content);
                    changeState(tkData);
                }
            });
            document.getElementById("fujian").style.display = "none";
        } else {
            var tkData=messageData[_index]
            $('.title').html(tkData.title);
            $('.adddate').html(tkData.adddate);
            $('.fbdw').html(tkData.fbdw);
            $('#content123').html(tkData.content);
            $("#id").attr("value",tkData.id);
            if(tabname=="通知公告"){
                $("#type").attr("value",'1');
                document.getElementById("fujian").style.display = "block";
            } else if(tabname=="政策文件"){
                $("#type").attr("value",'2');
                document.getElementById("fujian").style.display = "block";
            } else if(tabname=="经验推介"){
                $("#type").attr("value",'3');
                document.getElementById("fujian").style.display = "block";
            } else {
                //如果不是通知公告、政策文件、经验推介，隐藏下载附件按钮
                document.getElementById("fujian").style.display = "none";
            }
            changeState(tkData);
        }
        // 设置body不可滚动
        $('body').css({
            "overflow-x":"hidden",
            "overflow-y":"hidden"
        });
    });

    function changeState(tkData){
        var id = tkData.id;
        var type = tkData.type;
        $.ajax({
            url: "/main/changeState?id="+id+"&type="+type,
            type: "post",
            dataType: "json",
            success: function (data) {
            }
        });
    }

    $('.closeTK').on('click',function(){
        $('.tankuang').removeClass('tankuang-active');
        var aaa = document.getElementById("aaaa").getElementsByClassName("tab-item tab-active")[0];
        var tabname = aaa.textContent;
        if(tabname=="系统通知"){
            getMessageList("getXttzList");
        } else {
            getMessageList(messageType);
        }
        $('body').css({
            "overflow-y":"auto"
        });
    });

    /**
     * 根据分辨率的大小调整字体的大小
     * */
    styleQ("24px","20px","18px","16px");     //传入参数为 字体尺寸
    $(window).resize(function(){
        styleQ("24px","20px","18px","16px");     //传入参数为 字体尺寸
    });
    /**
     * 根据分辨率的大小调整字体的大小
     * */
    function styleQ(defaultFont,font1,font2,font3){
        var screenWidth=document.documentElement.clientWidth;
        if(screenWidth<=1880&&screenWidth>1560){
            $(".region-title").css("font-size",font1);
        }else if(screenWidth<=1560&&screenWidth>1400){
            $(".region-title").css("font-size",font2);
        }else if(screenWidth<=1400){
            $(".region-title").css("font-size",font3);
        }else{
            $(".region-title").css("font-size",defaultFont);
        }
    }
})